/*
 * @file test_creationclass.cpp
 */

/*****************************************************************************
**  $Id: test_creationclass.cpp 8865 2008-02-04 18:54:02Z andrew $
**
**  This is part of the dxflib library
**  Copyright (C) 2001 Andrew Mustun
**
**  This program is free software; you can redistribute it and/or modify
**  it under the terms of the GNU Library General Public License as
**  published by the Free Software Foundation.
**
**  This program is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**  GNU Library General Public License for more details.
**
**  You should have received a copy of the GNU Library General Public License
**  along with this program; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
******************************************************************************/

#include "hank_creationclass.h"

#include <iostream>
#include <stdio.h>

#include "dxf_tools.h"

/**
 * Default constructor.
 */
hank_CreationClass::hank_CreationClass() {}


/**
 * Sample implementation of the method which handles layers.
 */
void hank_CreationClass::addLayer(const hank::DL_LayerData& data) {
    //printf("\r\n LAYER: %s flags: %d\n", data.name.c_str(), data.flags);
    shape_layer * sp = new shape_layer() ;
    sp->m_name = attributes.getLayer()  ;
    dxf_tools_inst->fun_add_shape_by_layer_name( attributes.getLayer() , sp );
    //    printAttributes();
}

/**
 * Sample implementation of the method which handles point entities.
 */
void hank_CreationClass::addPoint(const hank::DL_PointData& data) {
    //    printf("\r\n POINT    (%6.3f, %6.3f, %6.3f)\n",  data.x, data.y, data.z);
    shape_point * sp = new shape_point() ;
    sp->m_point.m_x = data.x ;
    sp->m_point.m_y = data.y ;
    sp->m_point.m_z = data.z ;
    dxf_tools_inst->fun_add_shape_by_layer_name( attributes.getLayer() , sp );

    //    printAttributes();
}

/**
 * Sample implementation of the method which handles line entities.
 */
void hank_CreationClass::addLine(const hank::DL_LineData& data) {
    //    printf("\r\n LINE     (%6.3f, %6.3f, %6.3f) (%6.3f, %6.3f, %6.3f)\n",
    //           data.x1, data.y1, data.z1, data.x2, data.y2, data.z2);

    shape_line * sp = new shape_line() ;
    sp->m_point_start.m_x = data.x1 ;
    sp->m_point_start.m_y = data.y1;
    sp->m_point_start.m_z = data.z1 ;

    sp->m_point_end.m_x = data.x2 ;
    sp->m_point_end.m_y = data.y2 ;
    sp->m_point_end.m_z = data.z2 ;

    dxf_tools_inst->fun_add_shape_by_layer_name( attributes.getLayer() , sp );
    //    printAttributes();
}

/**
 * Sample implementation of the method which handles arc entities.
 */
void hank_CreationClass::addArc(const hank::DL_ArcData& data) {
    //    printf("\r\n ARC      (%6.3f, %6.3f, %6.3f) %6.3f, %6.3f, %6.3f\n",
    //           data.cx, data.cy, data.cz,
    //           data.radius, data.angle1, data.angle2);
    //    printAttributes();

    shape_arc * sp = new shape_arc() ;
    sp->m_point_c.m_x = data.cx ;
    sp->m_point_c.m_y = data.cy ;
    sp->m_point_c.m_z = data.cz ;

    sp->m_angle_1  = data.angle1   ;
    sp->m_angle_2  = data.angle2   ;
    sp->m_radius     = data.radius    ;

    dxf_tools_inst->fun_add_shape_by_layer_name( attributes.getLayer() , sp );

}

/**
 * Sample implementation of the method which handles circle entities.
 */
void hank_CreationClass::addCircle(const hank::DL_CircleData& data) {
    //    printf("CIRCLE   (%6.3f, %6.3f, %6.3f) %6.3f\n",
    //           data.cx, data.cy, data.cz,
    //           data.radius);
    //    printAttributes();
    shape_circ * sp = new shape_circ() ;
    sp->m_point_c.m_x = data.cx ;
    sp->m_point_c.m_y = data.cy ;
    sp->m_point_c.m_z = data.cz ;

    sp->m_radius     = data.radius    ;
    dxf_tools_inst->fun_add_shape_by_layer_name( attributes.getLayer() , sp );
}

/**
 * Sample implementation of the method which handles polyline entities.
 */
void hank_CreationClass::addPolyline(const hank::DL_PolylineData& data) {
    printf("\r\n POLYLINE \n");
    printf("flags: %d\n", (int)data.flags);
    printAttributes();
    shape_poly_line * sp = new shape_poly_line() ;

    dxf_tools_inst->m_curr_sp = sp ;
    dxf_tools_inst->fun_add_shape_by_layer_name( attributes.getLayer() , sp );
}

/**
 * Sample implementation of the method which handles vertices.
 */
void hank_CreationClass::addVertex(const hank::DL_VertexData& data) {
    //    printf("\r\n VERTEX   (%6.3f, %6.3f, %6.3f) %6.3f\n",
    //           data.x, data.y, data.z,
    //           data.bulge);
    //    printAttributes();

        point_   point__ ;
        point__.m_x = data.x ;
        point__.m_y = data.y ;
        point__.m_z = data.z ;
        point__.m_bulge = data.bulge ;
        dxf_tools_inst->m_curr_sp->m_points.push_back( point__ );

}


void hank_CreationClass::add3dFace(const hank::DL_3dFaceData& data) {
    printf("\r\n 3DFACE\n");
    for (int i=0; i<4; i++) {
        printf("   corner %d: %6.3f %6.3f %6.3f\n",
               i, data.x[i], data.y[i], data.z[i]);
    }
    printAttributes();
}

void hank_CreationClass::addSpline(const hank::DL_SplineData &)
{
    //    shape_spline

    shape_spline * sp = new shape_spline() ;

    dxf_tools_inst->m_curr_splise = sp ;

    dxf_tools_inst->fun_add_shape_by_layer_name( attributes.getLayer() , sp );

}

void hank_CreationClass::addControlPoint(const hank::DL_ControlPointData & data )
{
    point_   point__ ;
    point__.m_x = data.x ;
    point__.m_y = data.y ;
    point__.m_z = data.z ;
    point__.m_w = data.w ;

    dxf_tools_inst->m_curr_splise->m_control_points.push_back( point__ );
}

void hank_CreationClass::addFitPoint(const hank::DL_FitPointData & data )
{

}

void hank_CreationClass::addKnot(const hank::DL_KnotData & data )
{

}


void hank_CreationClass::printAttributes() {
    printf("  Attributes: Layer: %s, ", attributes.getLayer().c_str());
    printf(" Color: ");
    if (attributes.getColor()==256)	{
        printf("BYLAYER");
    } else if (attributes.getColor()==0) {
        printf("BYBLOCK");
    } else {
        printf("%d", attributes.getColor());
    }
    printf(" Width: ");
    if (attributes.getWidth()==-1) {
        printf("BYLAYER");
    } else if (attributes.getWidth()==-2) {
        printf("BYBLOCK");
    } else if (attributes.getWidth()==-3) {
        printf("DEFAULT");
    } else {
        printf("%d", attributes.getWidth());
    }
    //    printf(" Type: %s\n", attributes.getLineType().c_str());
}



// EOF
